Skip to content

fix(revm): 2d nonce gas schedule#1442

Merged
0xKitsune merged 14 commits into
tanishk/access-key-gas-schedulefrom
tanishk/gas-schedule-2dnonce
Dec 17, 2025
Merged

fix(revm): 2d nonce gas schedule#1442
0xKitsune merged 14 commits into
tanishk/access-key-gas-schedulefrom
tanishk/gas-schedule-2dnonce

Conversation

@legion2002

Copy link
Copy Markdown
Contributor

Adds a gas schedule for 2d nonces as written in the spec.
Without this the node can be susceptible to storage DOS vectors.

We also do a minor update in the gas schedule mentioned in the specs, to start the incrementing nonce costs from 20,000 instead of 0

@vercel

vercel Bot commented Dec 11, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Review Updated (UTC)
tempo-docs Ignored Ignored Preview Dec 17, 2025 6:23pm

Comment thread crates/revm/src/handler.rs Outdated
Comment thread crates/revm/src/handler.rs Outdated
Comment on lines +183 to +187
// New key - progressive cost based on number of active keys
let active_count = nonce_manager
.get_active_nonce_key_count(getActiveNonceKeyCountCall { account: caller })?;
Ok((active_count.saturating_to::<u64>() + 1) * NEW_NONCE_KEY_MULTIPLIER)
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm that seems super expensive and kinda breaks the usecase of using random nonce keys to not care about your nonces

after all it's just a cold sstore to non-existent slot which costs 22100 usually, why does it have to scale with number of active keys?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initially when we designed this dan and georgios were concerned about state bloat. We were discussing adding garbage collection and state rent, but unlike other state 2d nonces can never be garbage collected because it would lead to tx replay attacks.

So we wanted to limit the number of nonce keys a user could create.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think some of those concerns exist. But since we are relaxing our requirements for state bloat solutions, we can probably also relax them for 2d nonces.
This comes with the added benefit that we don't have to keep an active nonce key count.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated this to remove this linear gas cost for now, as I think the perf benefits of not having to keep track of the active nonce key count, alone makes it worth it.
When we update the new state creation gas costs, we can update this accordingly

Comment on lines +496 to +500
// Add 2D nonce gas to the initial gas
let adjusted_gas = InitialAndFloorGas::new(
init_and_floor_gas.initial_gas + evm.nonce_2d_gas,
init_and_floor_gas.floor_gas,
);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @rakita validate_initial_tx_gas should take &mut Evm so that we don't have to do this hack

@legion2002 legion2002 requested a review from fgimenez as a code owner December 12, 2025 10:48
@legion2002 legion2002 requested a review from howydev as a code owner December 15, 2025 21:56
@0xKitsune 0xKitsune merged commit 3a8653a into tanishk/access-key-gas-schedule Dec 17, 2025
16 of 18 checks passed
@0xKitsune 0xKitsune deleted the tanishk/gas-schedule-2dnonce branch December 17, 2025 19:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants